package com.duqc.quartz.scheduled;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.duqc.web.dao.CronMapper;
import com.duqc.web.entity.Scheduled;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;

/**
 * @ClassName TaskDemo
 * @Description TaskDemo
 * @Author duqc
 * @Date 2021/11/19
 **/
@Slf4j
@RequiredArgsConstructor
public class Task1Demo extends ConfigurerSchedulingDemo {

    private final CronMapper cronMapper;

    @Override
    public String getCron() {
        QueryWrapper<Scheduled> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name","demo2");
        return cronMapper.selectOne(queryWrapper).getCron();
    }

    @Override
    public void taskService() {
        Integer open = getOpen();
        if (1 == open) {
            log.info("定时任务demo2："
                    + LocalDateTime.now() + "，线程名称：" + Thread.currentThread().getName()
                    + " 线程id：" + Thread.currentThread().getId());
        }
    }

    private Integer getOpen() {
        QueryWrapper<Scheduled> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", "demo2");
        return cronMapper.selectOne(queryWrapper).getOpen();
    }
}
